#include "SDLINC.h"

#include <iostream>
#include <string>
#include "Game.h"
#include "Attributes.h"
#include "Graphics.h"
#include "Timer.h"


#define DEBUG false||DEBUG_ALL //set to true to turn on debug for this class only
#define DEBUG_FPS false||DEBUG //set to true to see fram per sec output


Game::Game(int argc, char* args[])
{
	this->graphics=new Graphics(this,argc,args);
	argc=argc;
	args=args;
	    
	if(DEBUG)
		std::cout<<"game \n";
//	string* name=new string("hello.bmp");	


}

Game::~Game()
{
	graphics->~Graphics();
}

void Game::mainGameLoop()
{
	bool quit=false;
	Timer fps;
	while(!quit)
	{
		fps.start();
		if(DEBUG)
			cout<<"begin main game loop\n";
		while(SDL_PollEvent(&event))//polling
		{

			if(event.type==SDL_QUIT)//exit flag
			{
				cout<<"exiting\n";
				quit=true;		
			}
		}
		
		if(DEBUG)
			cout<<"update\n";
		update();
		if(DEBUG)
			cout<<"render\n";
		render();	
		if( fps.get_ticks() < 1000 / FPS ) 
		{
			 SDL_Delay( ( 1000 / FPS ) - fps.get_ticks() ); 
		}
		if(DEBUG_FPS)
			cout<<"runing at "<<1000/fps.get_ticks()<<endl;
	
	}
}

void Game::update()
{
}


void Game::render()
{
	this->graphics->render();
}

